// 引入mongoose
const mongoose = require("mongoose");
// 引入优惠券模型
const { navsModel } = require("../db/model/navs");

//获取所有商品大类数据
const getNavsAll = async () => {
  const data = { rows: [] };
  data.rows = await navsModel.find();
  return data;
};

//新增商品大类
const addNav = async ({ name }) => {
  return await navsModel.create({
    name,
  });
};
// 删除商品大类数据
const delNav = async (_id) => {
  return await navsModel.deleteOne({ _id });
};
//通过id获取id对应商品大类的数据
const getOne = async (_id) => {
  return await navsModel.findOne({ _id });
};
//通过商品大类id修改商品大类的数据
const changeNav = async (newData) => {
  return await navsModel.updateOne({ _id: newData._id }, newData);
};
module.exports = {
  getNavsAll,
  addNav,
  delNav,
  changeNav,
  getOne,
};
